import { getAreaObj, uploadType } from '@/utils/util'
import { BaseFormConfig, ExtendFormConfig, OtherFormConfig } from './components/config'
import { toSearchHandle, configToSearch, configToReserveSearch } from '@/views/datacenter/basicData/utils/index'
import apiMod from '@/apiMod'

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '服务对象', prop: 'oldman', width: 200, showOverflowTooltip:false,custome: 'UserCard', align: 'left' },
		{ label: '户籍地区', prop: 'tableCrAreaName', fixed: true },
		{ label: '现居地区', prop: 'tableAreaName' },
		{
			label: '老人类别（政府兜底保障对象）',
			prop: 'elderlyType',
			custome: 'dict',
			width: 200,
			code: 'ELDERLY_TYPE',
		},
		// {
		// 	label: '居住情况',
		// 	prop: 'residence',
		// 	custome: 'dict',
		// 	code: 'LIVE_SITUATE',
		// },
		// {
		// 	label: '评估状态',
		// 	prop: 'evaluationStatusLabel',
		// },
		{ label: '入库时间', prop: 'createTime' },
		{
			label: '上链状态',
			prop: 'onBlockchainFlag',
			api: 'geiDictItemList',
			type: 'remoteSelect',
			code: 'BLOCK_CHAIN_STATUS',
			tipProp: 'onBlockchainTime',
			tipLabel: '上链时间',
		},
		{ label: '材料完整度', prop: 'integrity' },
		{
			label: '操作',
			prop: 'menu',
			width: 200,
			fixed: 'right',
		},
	],
}

export const rechangeConfig = {
	label: '变更材料',
	prop: 'dp_service_object_other',
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	submitBtnText: '确认并提交',
	backBtnText: '返回修改内容',
	column: [
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '变更内容',
			span: 24,
		},
		{
			prop: 'content',
			type: 'input',
			span: 24,
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '变更材料',
			span: 24,
		},
		{
			label: '情况说明',
			prop: 'changeDescription',
			type: 'textarea',
			maxlength: '140',
			rows: 2,
			showWordLimit: true,
			span: 24,
		},
		{
			label: '证明材料',
			prop: 'changeMaterials',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
		},
	],
}
const reserveSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [
		...configToReserveSearch(BaseFormConfig.column),
		// ...configToReserveSearch(ExtendFormConfig.column),
		// ...configToReserveSearch(OtherFormConfig.column),
	],
}
const moreSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToSearch(BaseFormConfig.column)],
	// column: [...configToSearch(BaseFormConfig.column), ...configToSearch(ExtendFormConfig.column), ...configToSearch(OtherFormConfig.column)],
}

export const dictcodes = [
	'VISITOR_ELDERLY_TYPE',
	'CHILDREN_SITUATION',
	'HOUSEING_PROPERTY',
	'LIVE_FLOOR',
	'LIVE_ROOM',
	'LIVE_TIME',
	'ID_CARD_TYPE',
	'REG_RESIDENCE_TYPE',
	'EXISTENCE_STATUS',
	'ELDERLY_DEMAND',
	'DISABILITY_TYPE',
	'DISABILITY_CLASS',
	'ELDERLY_TYPE',
	'BLOOD_TYPE',
	'NATIONALITY',
	'MARITAL_STATUS',
	'NURSE_TYPE',
	'OLDMAN_ZODIAC',
	'POLITICAL_STATUS',
	'ENJOY_TREATMENT',
	'SOCIAL_SECURITY',
	'EDUCATION_DEGREE',
	'RETIRE_TYPE',
	'RETIRE_WORK',
	'MEDICAL_SECURITY',
	'CARE_SITUATION',
	'SOCIAL_ACTIVITIES_SITUATE',
	'SOCIAL_ACTIVITIES_TYPE',
	'SPECIALTY',
	'MATERIAL_DATA_TYPE',
	'ELDERLY_RELATIONSHIP',
	'ECONOMIC_SITUATION',
	'INCOME_SOURCE',
	'DISPOSABLE_INCOME',
	'ACCESS_LEVEL_COUNTRY',
	'ACCESS_LEVEL_CITY',
	'LIVE_SITUATE',
	'RELIGIOUS_BELIEF',
	'SENIOR_LIVING',
	'EVALUATION_STATUS',
	'BLOCK_CHAIN_STATUS',
	'COMMON_FLAG',
]

export const detailConfig = {
	customeHeader: {
		integrityConfig: {
			baseTableName: 'dp_service_object',
			materialTableName: 'dp_service_object_material',
			soleValue: 'idCard',
		},
		type: 'CardTwo',
		title: 'name',
		avatar: 'image',
		tipList: [{ prop: 'telephone', type: 'tip-success', label: '联系电话' }],
		tagList: [
			{
				prop: 'countryLevel',
				propName: 'countryLevelLabel',
				code: 'ACCESS_LEVEL_COUNTRY',
				custome: 'tag',
				type: 'success',
				label: '能力等级',
			},
			{ prop: 'birthday', type: 'success', label: '公历' },
			{ prop: 'lunarBirthday', type: 'success', label: '农历' },
		],
		menuBtn: [
			{
				icon: 'delete',
				label: '删除服务对象',
				type: 'danger',
				operate: 'delete',
				auth: 'view_dpServiceObject_del',
				hide: 'dataStatus==0',
				text: false,
				show: true,
				plain: true,
			},
		],
	},
}
export const baseConfig = {
	pageName: '服务对象管理',
	dictcodes: dictcodes,
	rowKey: 'id',
	addLabel: '采集数据',
	tipLabel: 'name',
	needPigeonhole: true, // 是否显示顶部关于归档的部分
	exportMqTopic: [
		{
			topic: '/ning/export/dpServiceObject/',
			label: '基础数据',
			code: 1001,
			po: 'dpServiceObjectPO',
		},
		{
			topic: '/ning/export/dpServiceObjectExtend/',
			label: '扩展信息',
			code: 1003,
			po: 'dpServiceObjectExtendPO',
		},
		{
			topic: '/ning/export/dpServiceObjectContact/',
			label: '联系人信息',
			code: 1002,
			po: 'dpServiceObjectContactPO',
		},
		{
			topic: '/ning/export/dpServiceObjectOther/',
			label: '其他信息',
			code: 1005,
			po: 'dpServiceObjectOtherPO',
		},
		{
			topic: '/ning/export/dpServiceObjectMaterial/',
			label: '材料信息',
			code: 1004,
			po: 'dpServiceObjectMaterialPO',
		},
	],
	api: {
		moreSearch: 'view_search',
		reserveSearch: 'view_search                                       ',
		index: 'view_dpServiceObject_page',
		count: 'view_dpServiceObject_count',
		add: 'view_dpServiceObject_gather',
		edit: 'view_dpServiceObjectOther_edit',
		delete: 'view_dpServiceObject_del',
		export: 'view_dpServiceObject_exportAll',
	},
	auth: {
		index: 'view_dpServiceObject_page',
		add: 'view_dpServiceObject_gather',
		edit: 'view_dpServiceObjectOther_edit',
		delete: 'view_dpServiceObject_del',
		detail: 'view_dpServiceObjectAll_view',
		mulitSet: 'mulitSet',
		export: 'view_dpServiceObject_exportAll',
		import: 'view_dpServiceObject_page',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: 'view_dpServiceObjectAll_view',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '75%',
		// fullscreen: true
	},

	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'right',
		labelWidth: '100px',
		column: [
			{
				label: '证件号码',
				prop: 'idCard',
				type: 'input',
				span: 8,
			},
			{
				label: '户籍地区',
				prop: 'crAreas',
				checkStrictly: true,
				type: 'AplidAreaSelect',
				span: 8,
			},
			{
				label: '姓名',
				prop: 'name',
				type: 'input',
				span: 8,
			},
			{
				label: '联系方式',
				prop: 'telephone',
				type: 'input',
				span: 8,
			},
			{
				label: '服务对象类别',
				prop: 'elderlyType',
				type: 'remoteSelect',
				code: 'ELDERLY_TYPE',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
			},
			// {
			// 	label: '评估状态',
			// 	prop: 'evaluationStatus',
			// 	code: 'EVALUATION_STATUS',
			// 	type: 'remoteSelect',
			// 	api: 'getDictItemList',
			// 	filterKey: 'value',
			// 	multiple: false,
			// 	span: 6,
			// },
			// {
			// 	label: '居住状态',
			// 	prop: 'residence',
			// 	type: 'remoteSelect',
			// 	code: 'LIVE_SITUATE',
			// 	api: 'getDictItemList',
			// 	filterKey: 'value',
			// 	multiple: false,
			// 	span: 6,
			// },
			{
				label: '现居地区',
				prop: 'areas',
				checkStrictly: true,
				type: 'AplidAreaSelect',
				span: 8,
			},
		],
	},
	formConfig: {
		...OtherFormConfig,
		showBtn: true,
	},
	detailConfig,
	moreSearchConfig,
	// reserveSearchConfig,
	tableConfig,
	beforeOnLoadFormate: async (params) => {
		params = toSearchHandle(moreSearchConfig, reserveSearchConfig, params)
		let buildObj = {}
		if (params.buildInfo) {
			const buildName = params.buildInfoName?.split('/') || []
			buildObj = {
				checkinBuildingId: params.buildInfo[0],
				checkinFloor: params.buildInfo[1],
				checkinRoomId: params.buildInfo[2],
				checkinBedCodeId: params.buildInfo[3],

				checkinBuilding: buildName[0],
				checkinRoom: buildName[2],
				checkinBedCode: buildName[3],
			}
		}
		const areasObj: any = getAreaObj(params.areas, '')
		const crAreasObj: any = getAreaObj(params.crAreas, 'cr')
		const queryObj = {
			...params,
			...buildObj,
			...areasObj,
			...crAreasObj,
			areas: undefined,
			crAreas: undefined,
			buildInfo: undefined,
			buildInfoName: undefined,
		}
		return Promise.resolve({
			...queryObj,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const crAreaName = getAreaObj(item, 'cr')
			const areas_name = getAreaObj(item, '')
			return {
				...item,
				areas_name,
				crAreaName,
				tableAreaName: [item.areaName, item.streetName, item.communityName].filter(Boolean).join(''),
				tableCrAreaName: [item.crAreaName, item.crStreetName, item.crCommunityName].filter(Boolean).join(''),
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	operateFormate: async (form, type) => {
		return new Promise((resolve, reject) => {
			if (type == 'edit') {
				apiMod.view_dpServiceObjectOther_page({ idCard: form.idCard }).then((res) => {
					const data = res.data.records[0] || {}
					resolve({
						id: form.id,
						...data,
						idCard: form.idCard,
					})
				})
			} else {
				resolve(form)
			}
		})
	},
}
